#define _CRT_SECURE_NO_WARNINGS 1

#include<fstream>
#include<iostream>

using namespace std;

struct student
{
	char name[20];
	int num;
	int age;
	char sex;
};

int main()
{
	student stud[3];
	int i;
	ifstream infile("stud.dat", ios::binary);
	if (!infile)
	{
		cerr << "open error" << endl;
		abort();
	}
	for (int i = 0; i < 3; i++)
	{
		infile.read((char*)&stud[i], sizeof(stud[i]));
	}
	infile.close();
	for (int i = 0; i < 3; i++)
	{
		cout << "No." << i + 1 << endl;
		cout << "name:" << stud[i].name << endl;
		cout << "num:" << stud[i].num << endl;
		cout << "age:" << stud[i].age << endl;
		cout << "sex:" << stud[i].sex << endl;
	}
	return 0;
}
//
//int main()
//{
//	student stud[3] = { "li",1001,18,'f',"fang",1002,19,'m',"wang",1004,17,'f' };
//	ofstream outfile("stud.dat", ios::binary);
//	if (!outfile)
//	{
//		cerr << "open error" << endl;
//		abort();
//	}
//	for (int i = 0; i < 3; i++)
//	{
//		outfile.write((char*)&stud[i], sizeof(stud[i]));
//	}
//	outfile.close();
//	return 0;
//}